/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dipl.algorithm.math.fp.primitive;

/* vector in 2d real space */
public class Vector2df {

	//
	// CONSTRUCTOR METHODS
	//
	
	public Vector2df() {
		x = 0.0;
		y = 0.0;
	}

	public Vector2df( double x, double y ) {
		this.x = x;
		this.y = y;
	}

	public Vector2df( Vector2df other ) {
		x = other.x;
		y = other.y;
	}

	//
	// PUBLIC METHODS
	//

	/**
	 * Returns norm (euclidian norm) of vector
	 * @param norm
	 * @return
	 */
	public double Norm() {
		return Math.sqrt( x*x+y*y );
	}

	/*
	 * normalizes vector
	 */
	public void Normalize() {
		double len = Norm();
		// len is  zero
		if( len == 0.0 )
			return;
		x /= len;
		y /= len;
	}

	/**
	 *  Returns norm² (square of euclidian norm) of vector
	 */
	public double SquareNorm() {
		return x*x+y*y;
	}

	/**
	 * 
	 * @param other
	 */
	public void Set( Vector2df other ) {
		x = other.x;
		y = other.y;
	}

	/**
	 * 
	 * @param x
	 * @param y
	 */
	public void Set( double x, double y ) {
		this.x = x;
		this.y = y;
	}

	@Override
	public String toString() {
		return "x:"+Double.toString( x )+", y:"+Double.toString( y );
	}

	//
	// MEMBERS
	//

	/** x-element */
	public double x;

	/** y-element */
	public double y;
}
